package info.pablo.greet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.regex.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



/**
 * Servlet implementation class SignIn
 */
@WebServlet("/SignIn")
public class SignIn extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SignIn() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
	
	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter output = response.getWriter();
		String login = request.getParameter("login");
		String dni = request.getParameter("dni");
		//String email = request.getParameter("email");
	
		//We chech login value using regex
	Pattern pattern = Pattern.compile("^[a-z]{8}$");//esto lo que hace es : de principio a fin 8 caracteres
	Matcher loginChecker = pattern.matcher(login);
	
	if(loginChecker.find()){
		output.write("Ok login cumple <br />");
	}else{
		output.write("No login cumlpe <br />");
	}
	 pattern = Pattern.compile("[0-9]{8}[a-z]");
	 loginChecker = pattern.matcher(dni);
	 
	 if(loginChecker.find()){
			output.write("Ok login cumple <br />");
		}else{
			output.write("No login cumlpe <br />");
		}
	 this.getServletContext()
	 	.getRequestDispatcher("/login.jsp")
	 		.forward(request, response);
	/** pattern = Pattern.compile("[0-9]{8}[a-z]");
	 loginChecker = pattern.matcher(dni);
	 
	 if(loginChecker.find()){
			output.write("Ok login cumple <br />");
		}else{
			output.write("No login cumlpe <br />");
		}*/
	
	}

}
